""" article模型 """


from sqlalchemy import Column, ForeignKey, Integer, String
from sqlalchemy.orm import relationship

from database.database import Base


class Article(Base):
    __tablename__ = "article"

    id = Column(Integer, primary_key=True, index=True, autoincrement=True)
    title = Column(String, nullable=False)
    description = Column(String, nullable=False)
    content = Column(String, nullable=False)
    created_at = Column(Integer, nullable=True)
    updated_at = Column(Integer, nullable=True)

    cate_id = Column(Integer, ForeignKey("category.id"))
    category = relationship("Category", back_populates="articles")

    def to_dict(self):
        return {c.name: getattr(self, c.name) for c in self.__table__.columns}
